import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'
// 根据id查询详细信息
export function getDetailData(id) {
  return request({
    url: `/api/v1/shopSurvey/${id}`,
    method: 'get'
  })
}

// 保存测绘申请
export function saveMapData(data, type) {
  if (type === 1) { // 保存
    return request({
      url: data.id ? '/api/v1/shopSurvey/updateShopSurvey' : '/api/v1/shopSurvey/insertShopSurvey',
      method: data.id ? 'post' : 'put',
      data
    })
  } else { // 编辑
    return request({
      url: '/api/v1/shopSurvey/submitShopSurvey',
      method: 'put',
      data
    })
  }
}
// 批量提交任务
export function submitBatch(data) {
  return request({
    url: '/api/v1/shopSurvey/batchCommit',
    method: 'post',
    data
  })
}

// 保存安排测绘,执行测绘,复尺执行,不复尺执行
export function saveState(data) {
  return request({
    url: '/api/v1/shopSurvey/updateState',
    method: 'post',
    data
  })
}

// 申请延期  异常
export function saveException(data) {
  return request({
    url: `/api/v1/shopException`,
    method: 'post',
    data
  })
}

// 执行测绘--批量删除文件 todo
export function deleteFileBatch(data) {
  return request({
    url: '',
    method: 'delete',
    data
  })
}

// 获取附件类型
export function getTypeOption() {
  return request({
    url: `/api/v1/configAttachmentTemplate/page`,
    method: 'post'
  })
}

/**
 * 根据所属模块获取文件列表
 * @returns
 */
export function postConfigAttachmentTemplate() {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('belongModel', 'SHOP_SURVEY', '=')]))
  return request({
    url: '/api/v1/configAttachmentTemplate/page',
    method: 'POST',
    data
  })
}
/**
 * 根据门店编码获取门店建设项目号
 * @returns
 */
export function searchConstCode(code) {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('shopCode', code, '='), otherFiltersItem('isEnd', '0', '='), otherFiltersItem('belongStage', '[SHOP_SURVEY,SHOP_DESIGN,LOCATION_EVAL]', 'in')]))
  return request({
    url: '/api/v1/shopConstruct/allPage',
    method: 'POST',
    data
  })
}
/**
 * 根据办事处编码获取办事处性质
 * @returns
 */
export function searchOfficeNature(code) {
  return request({
    url: `/api/v1/shopSurvey/getAgencyByCode/${code}`,
    method: 'POST'
  })
}

// 终止任务
export function saveTerminal(data) {
  return request({
    url: '/api/v1/shopSurvey/stopShopSurvey',
    method: 'post',
    data
  })
}

/**
 *
 * @param {*} 门店建设项目号
 * @returns
 */
export function isConfirm(data) {
  return request({
    url: '/api/v1/shopSurvey/stopConfirm',
    method: 'post',
    data
  })
}
